<?

	include("inc/config.inc.php");
    
    include("inc/header.inc.php");

	$edit = mysqli_real_escape_string($con,$_GET[e]);

	// Check we are HR!
	if ($_SESSION[role] != "HR")
		die ("Error 41 - User error - Please contact support.");

	echo "<h2><span class='textColorChange'>$config[systemtitle]</span></h2><br/>\n\n";

    echo "<a href='main.php' style='color:black;font-size:10pt'><< Back</a><br/>";

    echo "<div style='background:#504E52' class='normalText' width='400'>\n";

	echo "<b>Manage Bank Holidays</b><br/><br/>\n";
	echo "Any dates listed here will NOT count against holiday allowance if booked in a holiday request period.<br/><br/>\n";

	// Get all users, show prestages ones first as they require attention
	$result = mysqli_query($conn, "SELECT * FROM bankhols ORDER BY date DESC");
	if (mysqli_num_rows($result) > 0)
	{

		// Form validation
		echo "<script>
		function validateForm()
		{
			if (document.forms['form']['hid'].value == '' || document.forms['form']['date'].value == '' || document.forms['form']['name'].value == '')
			{
				alert('Please fill in all fields!');
				return false;
			}
		}

		$(function() {
		$('#datepicker').datepicker({
			dateFormat: 'yy-mm-dd'
		});
		});




		</script>
		";
				

		echo "<table BORDERCOLORLIGHT='#807E7C' BORDERCOLORDARK='#383634' border='1'><tr><td>Date</td><td>Name</td><td>Action</td></td></tr>";
		
		//Not editing, show first row as insert row
		//if ($edit == "")
		//{
			echo "<form name='form' action='updatebhol.php' method='POST' onsubmit='return validateForm()'><input type='hidden' name='new' value='true'>";
			echo "<tr><td><input type='text' name='date' id='datepicker'></td><td><input type='text' name='name'></td><td><input type='submit' value='Save'></td></tr>";
			echo "</form>";
		//}
		
		while ($b = mysqli_fetch_array($result))
		{

				echo "<tr>\n";

			// Row for editing
			if ($edit == $b[hid])
			{
				echo "<form name='form' action='updatebhol.php' method='POST' onsubmit='return validateForm()'>";
				echo "<input type='hidden' name='hid' value='$b[hid]'>\n";
				echo "<td><input type='text' name='date' value='$b[date]' id='datepicker'></td>\n";
				echo "<td><input type='text' name='name' value='$b[name]'></td>\n";
			}
			
			// Regular view row
			else
			{
				echo "<td>$b[date]</td>\n";
				echo "<td>$b[name]</td>\n";
			}

			// Actions
			if($edit == $b[hid])
				echo "<td><input type='submit' value='Save'> <input type='button' value='Cancel' onClick='location.href=\"bhol.php\"'></td></form></tr>\n";
			else
			{
				echo "<td><a href='bhol.php?e=$b[hid]'><img src='img/application_edit.png' width='16' height='16' border='0' Alt='Edit'></a> \n";
				echo "<a href='bholdel.php?e=$b[hid]' onClick='return confirmDelete(\"delete\");'><img src='img/delete.png' width='16' height='16' border='0' alt='Delete'></a></td></tr>\n";
			}
				
		}
		echo "</table>\n";

	}

	echo "</div>\n";

	include("inc/footer.inc.php");
    
?>
    
